<?php
require_once dirname(__FILE__) . '/../../../incls/php/config.php';
require_once dirname(__FILE__) . '/../../../incls/php/miscutils.class.php';
require_once dirname(__FILE__) . '/../../../incls/php/dbutils.class.php';

$url = MiscUtils::getParam('url', NULL);
$path = basename(dirname(__FILE__));
$sys_script = $system->script;

$bg_images = scandir('exts/uis/'.  $path . '/assets/imgs/bg/');
$idx = rand() % count($bg_images);
if (substr($bg_images[$idx], 0, 1) == '.') {
 $idx = 3;
}
?>
<html>
<head>
<title><?php echo $system->title; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
* {
  font-family: Trebuchet MS;
  font-size: 12px;
  outline: 0;
  margin: 0;
}
body {
  background-image: url(exts/uis/<?php echo $path; ?>/assets/imgs/bg/<?php echo $bg_images[$idx];?>);
  background-repeat: no-repeat;
}
.superscript {
  background-image: url(exts/uis/<?php echo $path; ?>/assets/imgs/topbg.png);
  background-repeat: repeat-x;
  text-align: center;
  height: 41px;
  width: 100%;
  z-index: 9999;
}
<?php echo $page->css; ?>


</style>
</head>
<body>
<div class="superscript">
  <?php include dirname(__FILE__) . '/index_menu.php'; ?>
</div>
<div style="min-height: 550px; background-image: url(exts/uis/<?php echo $path; ?>/assets/imgs/bg.png);">
  <div>
    <?php include dirname(__FILE__) . '/index_nav.php'; ?>
  </div>
  <div style="padding: 0 0 0 8px;">
    <?php echo $page->html; ?>
  </div>
</div>
<script type="text/javascript">
  <?php echo $page->js; ?>
  function nav(entries) {
    var table, tr, td, elm;
    elm = document.getElementById('nav');
    elm.style.height = '';
    elm.style.paddingBottom = '15px';
    while (elm.firstChild) {
      elm.removeChild(elm.firstChild);
    }
    table = document.createElement('table');
    elm.appendChild(table);
    tr = table.insertRow(-1);
    for (var idx in entries) {
      var obj = entries[idx];
      td = tr.insertCell(-1);
      td.className = 'nav';
      if (obj.href == '') {
        td.appendChild(document.createTextNode(obj.name));
      } else {
        elm = document.createElement('a');
        elm.href = obj.href;
        elm.appendChild(document.createTextNode(obj.name));
        td.appendChild(elm);
      }
      if (idx != entries.length - 1) {
        td = tr.insertCell(-1);
        td.className = 'arrow';
        td.appendChild(document.createTextNode('>'));
      }
    }
  };
</script>
</body>
</html>
<?php 

function _createMenuRoot($arr, $node) {
  for ($i = 0, $il = count($arr); $i < $il; $i++) {
    $tmp = $arr[$i];
    if ($tmp->is_visible == 0) {
      continue;
    }
    if ($tmp->parent_id == $node->id) {
      $tmp->link = '?i=' . $tmp->id;
      $tmp->name = $tmp->title;
      $tmp->c = array();
      $node->c[] = $tmp;
      _createMenuRoot($arr, $tmp);
    }
  }
}

function _createMenuRoot2($arr, $node) {
  for ($i = 0, $il = count($arr); $i < $il; $i++) {
    $tmp = $arr[$i];
    if ($tmp->parent_id == $node->id) {
      $tmp->link = '?i=' . $tmp->id;
      $tmp->name = $tmp->title;
      $tmp->c = array();
      $node->c[] = $tmp;
      _createMenuRoot2($arr, $tmp);
    }
  }
}

function _getNav($root, $id) {
  $array = array();
  return _find($root, $id, $array);
}

function _find($haystack, $needle, $array) {
  if ($haystack->id == $needle) {
    return $array;
  }
  foreach ($haystack->c as &$tmp) {
    array_push($array, $tmp);
    $result = _find($tmp, $needle, $array);
    if ($result != NULL) {
      return $result;
    }
    array_pop($array);
  }
  return array();
}

?>
